﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _3Dshower
{
    public class Point
    {
        private double[] coor;//坐标信息,xyz
        private int dimension;//维数
        //x,z平面上的角
        private double horizontalAngle;
        private double horizontalLength;
        //y，z平面上的角
        private double verticalAngle;
        private double verticalLength;
        private double Length;//长度
        private double getAngle(double x, double y)
        {
            if (x> 0)
                return Math.Atan(y/ x);
            if (x < 0)
                return Math.Atan(y / x) + Math.PI;
            if (y> 0)
                return Math.PI / 2;
            return -Math.PI / 2;
        }
        public void ReCal_CoorToAngle()
        {
            Length = Math.Sqrt(coor[0] * coor[0] + coor[1] * coor[1] + coor[2] * coor[2]);
            horizontalLength= Math.Sqrt(coor[0] * coor[0] + coor[2] * coor[2] );
            verticalLength = Math.Sqrt(coor[2] * coor[2] + coor[1] * coor[1]);
            horizontalAngle=getAngle(coor[0],coor[2]);
            verticalAngle = getAngle(coor[1], coor[2]);
        }
        private void ReCal_HorAngToCoor()
        {
            coor[0] = horizontalLength * Math.Cos(horizontalAngle);
            coor[2] = horizontalLength * Math.Sin(horizontalAngle);
            verticalLength = Math.Sqrt(coor[2] * coor[2] + coor[1] * coor[1]);
            verticalAngle = getAngle(coor[1], coor[2]);
        }
        private void ReCal_VerAngToCoor()
        {
            coor[1] = verticalLength* Math.Cos(verticalAngle);
            coor[2] = verticalLength * Math.Sin(verticalAngle);
            horizontalLength = Math.Sqrt(coor[0] * coor[0] + coor[2] * coor[2]);
            horizontalAngle = getAngle(coor[0], coor[2]);
        }

        public Point(params double[] p)
        {
            this.Coor = p;
        }
        public double[] Coor
        {
            get { return coor; }
            set
            {
                dimension = value.Length;
                coor = value;
                ReCal_CoorToAngle();
            }
        }
        public void changeCoor(Point moveDir)
        {
            for (int i = 0; i < moveDir.Coor.Length;++i )
            {
                coor[i] += moveDir.Coor[i];
            }
            ReCal_CoorToAngle();
        }
        public void changeHorAngle(double Angle)
        {
            horizontalAngle += Angle;
            ReCal_HorAngToCoor();
        }
        public void changeVerAngle(double Angle)
        {
            verticalAngle += Angle;
            ReCal_VerAngToCoor();
        }

        
    }
}
